package cn.hf.mychat.teach.service;

import cn.hf.mychat.teach.commonenum.CommonEnum;
import cn.hf.mychat.teach.mapper.TeachMapper;
import cn.hf.mychat.teach.model.LookupItem;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.FractionFormat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.text.DecimalFormat;
import java.text.Format;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

@Service
@RequiredArgsConstructor
public class TeachService {
    @Autowired
    private TeachMapper teachMapper;


    @Scheduled(cron = ("0 0 9 ? * *"))
    public boolean sendMail() {
        Boolean flag = false;
        String ip = getIp();
        if (!CommonEnum.API_IP.getCode().equals(ip)) {
            return flag;
        }
        //配置表
        //String role=teachMapper.getOrgID(um);
        //if(StringUtils.isNotBlank(role)){}else {}
//TODO

        return flag;
    }

    public String getIp() {
        return teachMapper.getIp();
    }

    ;

    public ArrayList<HashMap<String, String>> getChance() {
        //1.替换
        String str = "oqi nen${userName}fr\\s";
        String newStr = str.replace("${userName}", "xiaoming");
        newStr = str.replaceAll(" ", "&nbsp;");
        newStr = str.replaceAll("\\s*", " ");
        newStr = str.replaceAll("&quot", "\"");

        Integer integer = 9;
        String s = String.valueOf(integer);

        //2,修改返回的字段
        HashMap<String, String> map = new HashMap<>();
        map.put("A", "1");
        map.put("B", "2");
        ArrayList<HashMap<String, String>> arrayList = new ArrayList<>();
        arrayList.add(map);
        for (int i = arrayList.size() - 1; i >= 0; i--) {
            HashMap<String, String> newMap = new HashMap<>();
            HashMap<String, String> hashMap = arrayList.get(i);
            newMap.put("a", hashMap.get("A"));
            newMap.put("b", hashMap.get("B"));
            arrayList.remove(i);
            arrayList.add(newMap);
        }
        //3.配置字典
        List<LookupItem> list = teachMapper.getLookup("INFO");
        for (int i = 0; i < list.size(); i++) {
            String code = list.get(i).getFCode();
            String value = list.get(i).getFValue();
            if ("A".equals(code)) {
                if (StringUtils.isNotBlank(value)) {
                    String[] a = value.split(";");

                }
            } else if ("b".equals(code)) {
                if (StringUtils.isNotBlank(value)) {
                    String[] b = value.split(";");

                }
            } else if ("c".equals(code)) {
                String str1 = value;
                String c = str1.replace("${userName}", "xiaoming");
                c = str1.replaceAll(" ", "&nbsp;");
                c = str1.replaceAll("\\s*", " ");
                c = str1.replaceAll("&quot", "\"");
            }
        }
        if (!CollectionUtils.isEmpty(list)) {
            if (list.contains("2")) {
                list.size();
            }
        }

        if (str.startsWith("111")) {
            str.charAt(1);
        } else if (str.endsWith("222")) {
            str.split(",", 9);
        }
        if(arrayList.contains("1")){
            System.out.println("list = " + list);
        }

        //4小数处理
        Integer a=122;
        DecimalFormat format = new DecimalFormat("#0.00");
        Integer a1 = Integer.parseInt(format.format(a));//122.00

        return arrayList;
    };
}
